package com.music.service.Impl;

import com.music.mapper.CommentMapper;
import com.music.pojo.CommentExample;
import com.music.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentMapper commentMapper;
    @Override
    public Long countByMid(Integer mid) {
        CommentExample commentExample = new CommentExample();
        CommentExample.Criteria criteria = commentExample.createCriteria();
        criteria.andMidIn(Collections.singletonList(mid));
        return commentMapper.countByExample(commentExample);
    }

    @Override
    public void addComment(Integer mid, Integer cid, Integer uid, String commentText) {
        if(cid==null){
            commentMapper.addCommentToSong(mid,uid,commentText);
        }else {
            commentMapper.addCommentToUser(mid,cid,uid,commentText);
        }
    }
}
